$(function(){
	$.ajax({  
		type: 'POST',
		dataType: "json",
		url:'../getNavigationResource',
		success: function(data){
			$.each(data,function(i,n){
				$('#functions').accordion('add',{
					title: n.name,
					selected: false,
					content:'<div style="padding:10px"><ul name="'+n.name+'"></ul></div>',
				});
			});
		}
	}); 
	 //异步加载子节点，即二级菜单  
    $('#functions').accordion({  
        onSelect : function(title, index) {  
            $("ul[name='" + title + "']").tree({  
                url : '../getSource',  
                queryParams : {  
                    text : title  
                },  
                animate : true,  
                lines : true,//显示虚线效果    
                onClick: function(node){// 在用户点击一个子节点即二级菜单时触发addTab()方法,用于添加tabs  
                    if(node.url){//判断url是否存在，存在则创建tabs  
                        addTab(node.srcname,node.srcuri);  
                    }  
                }  
            });  
        }  
    });
	var functions=$('#functions');
	var resources=$('#srcCrol');
	resources.click(function(){
		var title=$('#src');
		addTab(title.text(),'../index/resource');
	});
	var navigation=$('#navCrol');
	navigation.click(function(){
		var title=$('#nva');
		addTab(title.text(),'../index/navigation');
	});
	var dashboard=$('#dashCrol');
	dashboard.click(function(){
		var title=$('#dashboard');
		addTab(title.text(),'../index/dashboard');
	});
	function addTab(title, url){
		if ($('#tt').tabs('exists', title)){
			$('#tt').tabs('select', title);
		} else {
			var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
			$('#tt').tabs('add',{
				title:title,
				content:content,
				closable:true
			});
		}
	}
});